package com.onLineCar.netty.serve;

import com.onLineCar.common.redis.service.RedisService;
import com.onLineCar.netty.protocol.command.AMapRequestPacket;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @program: OnLineCar
 * @description:
 * @author: godGuang
 * @create: 2023-12-21 16:28
 **/
@Component
@ChannelHandler.Sharable
public class AMapRequestHandler extends SimpleChannelInboundHandler<AMapRequestPacket> {
    @Autowired
    private RedisService redisService;

    // 公共构造函数用于依赖注入
    public AMapRequestHandler(RedisService redisService) {
        this.redisService = redisService;
    }
    @Bean("aMapRequestHandler")
    public AMapRequestHandler createAMapRequestHandler() {
        return new AMapRequestHandler(redisService);
    }
    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, AMapRequestPacket aMapRequestPacket) throws Exception {
        String orderTrajectory = aMapRequestPacket.getOrderTrajectory();
        String userName = aMapRequestPacket.getUserName();
        /**
         * 存入redis做缓存
         * key: 订单编号
         * hk: 用户名
         * value: 订单轨迹
         */
        redisService.setCacheMapValue("订单编号666", userName, orderTrajectory);

    }
}

